<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>供应商开启扫码收货二维码管理</title>
    <link rel="stylesheet" href="/Public/layui/css/layui.css"/>
    <script type="text/javascript" src="/Public/layui/layui.js"></script>

</head>
<style>
    html,body{
        background-color: #fff;
    }
    .qrCode {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 400px;
        height: 400px;
        background-color: #fff;
    }
</style>
<body>
    <div class="qrCode">
        <div style="text-align:center;">
            <div id="qrcode" style="display:inline-block;"></div>
        </div>

        <div align="center" style="margin-top: 100px;">
            <button class="layui-btn layui-btn-sm layui-icon layui-icon-print" id="refurbish" >刷新</button>
        </div>

    </div>
</body>
</html>
<script type="text/javascript" src="/Public/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/Public/js/jquery.qrcode.min.js"></script>
<script>
    $(function (){
        createQrCode();

        var timer = setInterval(function () {
            //每5秒刷新二维码
            createQrCode();
        },5000);

        $('#refurbish').on('click', function(){
            //操作锁，防止重复点击触发
            var lock=false;
            if(!lock){
                lock = true;
                //$('#printOrder').addClass('layui-btn-disabled');
                var order_no=$('#order_no').text();

                createQrCode();
            }
        });
    })

    function createQrCode(){
        let curr_time2 = getCurrentTime();
        console.log("生成二维时间：" + curr_time2);

        //生成二维码之前先清理一下
        $('#qrcode').html("")

        let curr_time = getCurrentTime();
        let orderNo ={curr_time:curr_time,codeType:3};//codeType:1-供应商；2-司机；3-供应商开启扫码
        orderNo = JSON.stringify(orderNo)
        $('#qrcode').qrcode({
            render: "canvas",
            text: orderNo,
            width: 350,               //二维码的宽度
            height: 350,              //二维码的高度
            background: "#ffffff",      //二维码的后景色
            foreground: "#000000",      //二维码的前景色
        });
    }

    function getCurrentTime() {
        var date = new Date();//当前时间
        var year = date.getFullYear() //返回指定日期的年份
        var month = repair(date.getMonth() + 1);//月
        var day = repair(date.getDate());//日
        var hour = repair(date.getHours());//时
        var minute = repair(date.getMinutes());//分
        var second = repair(date.getSeconds());//秒

        //当前时间
        var curTime = year + "-" + month + "-" + day
            + " " + hour + ":" + minute + ":" + second;
        return curTime;
    }

    //补0
    function repair(i){
        if (i >= 0 && i <= 9) {
            return "0" + i;
        } else {
            return i;
        }
    }
</script>